package com.roamer.school.common.util;

/**
 * 字符串 工具类
 *
 * @author roamer
 * @version V1.0
 * @date 2019/1/20 14:06
 * @see org.apache.commons.lang3.StringUtils
 */
public class StringUtils {

    /**
     * Checks if a CharSequence is empty ("") or null
     *
     * <pre>
     *      StringUtils.isEmpty(null)      = true
     *      StringUtils.isEmpty("")        = true
     *      StringUtils.isEmpty(" ")       = false
     *      StringUtils.isEmpty("bob")     = false
     *      StringUtils.isEmpty("  bob  ") = false
     * </pre>
     *
     * @param cs 需检查的字符串
     *
     * @return {@code true} if the CharSequence is empty or null
     *
     * @see org.apache.commons.lang3.StringUtils#isEmpty(CharSequence)
     */
    public static boolean isEmpty(final CharSequence cs) {
        return org.apache.commons.lang3.StringUtils.isEmpty(cs);
    }

    /**
     * Checks if a CharSequence is not empty ("") and not null
     *
     * @param cs 需检查的字符串
     *
     * @return {@code true} if the CharSequence is not null and not empty ("")
     */
    public static boolean isNotEmpty(final CharSequence cs) {
        return !isEmpty(cs);
    }

    /**
     * Checks if a CharSequence is empty (""), null or whitespace only
     *
     * <pre>
     * StringUtils.isBlank(null)      = true
     * StringUtils.isBlank("")        = true
     * StringUtils.isBlank(" ")       = true
     * StringUtils.isBlank("bob")     = false
     * StringUtils.isBlank("  bob  ") = false
     * </pre>
     *
     * @param cs 需检查的字符串
     *
     * @return {@code true} if the CharSequence is empty, null or whitespace only
     *
     * @see org.apache.commons.lang3.StringUtils#isBlank(CharSequence)
     */
    public static boolean isBlank(final CharSequence cs) {
        return org.apache.commons.lang3.StringUtils.isBlank(cs);
    }

    /**
     * Checks if a CharSequence is not empty ("") and not null and not whitespace only
     *
     * @param cs 需检查的字符串
     *
     * @return {@code true} if the CharSequence is not empty and not null and not whitespace only
     */
    public static boolean isNotBlank(final CharSequence cs) {
        return !isBlank(cs);
    }

    /**
     * Checks if a CharSequence is not null and length > 0
     *
     * @param cs 需检查的字符串
     *
     * @return {@code true} if the CharSequence is not null and length > 0
     */
    public static boolean hasLength(final CharSequence cs) {
        return isNotEmpty(cs);
    }

    /**
     * Checks if a CharSequence is not empty and not null and not whitespace only
     *
     * @param cs 需检查的字符串
     *
     * @return {@code true} if the CharSequence is not empty and not null and not whitespace only
     */
    public static boolean hasText(final CharSequence cs) {
        return isNotBlank(cs);
    }


    /**
     * Replace all occurrences of a substring within a string with another string.
     *
     * @param inString   {@code String} to examine
     * @param oldPattern {@code String} to replace
     * @param newPattern {@code String} to insert
     *
     * @return a {@code String} with the replacements
     *
     * @see org.springframework.util.StringUtils#replace(String, String, String)
     */
    public static String replace(String inString, String oldPattern, String newPattern) {
        return org.springframework.util.StringUtils.replace(inString, oldPattern, newPattern);
    }
}
